package io.cw.service.impl.iml.background;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.cw.dao.background.RelRoomTimeDao;
import io.cw.entity.background.RelRoomSeatEntity;
import io.cw.entity.background.RelRoomTimeEntity;
import io.cw.service.impl.background.RelRoomTimeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 教室预约时段 服务类
 *
 * @author cw
 */
@Service
public class RelRoomTimeServiceImpl extends ServiceImpl<RelRoomTimeDao, RelRoomTimeEntity> implements RelRoomTimeService {


    @Override
    @Transactional
    public void batchInsert(List<RelRoomTimeEntity> entityList) {
        this.saveBatch(entityList);
    }

    @Override
    public List<RelRoomTimeEntity> findByRoomIds(List<String> roomIds) {
        return this.lambdaQuery().in(RelRoomTimeEntity::getRoomId, roomIds)
                                 .eq(RelRoomTimeEntity::getIsValid, 1)
                                 .orderByAsc(RelRoomTimeEntity::getStartTime).list();
    }

    @Override
    public void delateByRoomId(String roomId) {
        QueryWrapper<RelRoomTimeEntity> deleteWrapper = new QueryWrapper();
        deleteWrapper.lambda().eq(RelRoomTimeEntity::getRoomId, roomId);
        this.remove(deleteWrapper);
    }
}
